﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;
using System;

namespace IFRS.DataAccess.DAL
{
    public class SPR_FEEANDCOSTTYPE
    {
        public DataTable SEARCH_ALL(FeeAndCostType FeeAndCostType, Paging paging, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@DataType", FeeAndCostType.DataType.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsIncludeAmortizeCost", FeeAndCostType.IsIncludeAmortizeCost.AsDBValue()));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeCode", FeeAndCostType.FeeAndCostTypeCode.AsDBValue()));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeName", FeeAndCostType.FeeAndCostTypeName.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_FEEANDCOSTTYPE_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }
        public DataTable SEARCH_ALLWIN24(FeeAndCostType FeeAndCostType, Paging paging, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@CreatedDate", FeeAndCostType.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeID", FeeAndCostType.FeeAndCostTypeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@ChangeStatus", FeeAndCostType.ChangeStatus.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_FEEANDCOSTTYPEWIN24_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_ALL_POPUP(FeeAndCostType FeeAndCostType, Paging paging, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeCode", FeeAndCostType.FeeAndCostTypeCode.AsDBValue()));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeName", FeeAndCostType.FeeAndCostTypeName.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_FEEANDCOSTTYPE_POPUP_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int iFeeAndCostTypeID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@FeeAndCostTypeID", iFeeAndCostTypeID));
                dt = Utility.StoredProcDataTable("SPR_FEEANDCOSTTYPE_SEARCHBYID", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(FeeAndCostType FeeAndCostType)
        {
            int iNum;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@FeeAndCostTypeID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;

                lstParams.Add(new SqlParameter("@DataType", FeeAndCostType.DataType));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeCode", FeeAndCostType.FeeAndCostTypeCode));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeName", FeeAndCostType.FeeAndCostTypeName));
                lstParams.Add(new SqlParameter("@IsIncludeAmortizeCost", FeeAndCostType.IsIncludeAmortizeCost));
                lstParams.Add(new SqlParameter("@CreatedDate", FeeAndCostType.CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", FeeAndCostType.CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", FeeAndCostType.CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", FeeAndCostType.CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", FeeAndCostType.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", FeeAndCostType.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", FeeAndCostType.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", FeeAndCostType.UpdatedBranch));

                utility.ExecuteStoredProc("SPR_FEEANDCOSTTYPE_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(FeeAndCostType FeeAndCostType)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@FeeAndCostTypeID", FeeAndCostType.FeeAndCostTypeID));
                lstParams.Add(new SqlParameter("@DataType", FeeAndCostType.DataType));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeCode", FeeAndCostType.FeeAndCostTypeCode));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeName", FeeAndCostType.FeeAndCostTypeName));
                lstParams.Add(new SqlParameter("@IsIncludeAmortizeCost", FeeAndCostType.IsIncludeAmortizeCost));
                lstParams.Add(new SqlParameter("@UpdatedDate", FeeAndCostType.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", FeeAndCostType.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", FeeAndCostType.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", FeeAndCostType.UpdatedBranch));

                iNum = (int)Utility.ExecuteStoredProc("SPR_FEEANDCOSTTYPE_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(int iFeeAndCostTypeID)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@iFeeAndCostTypeID", iFeeAndCostTypeID));
                iNum = (int)Utility.ExecuteStoredProc("SPR_FEEANDCOSTTYPE_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

    }
}
